package logger

import (
	"log"
	"mychat/internal/conf"
)

type stdLogger struct {
	baselogger
}

func NewStdLogger(cl *conf.Logger) Logger {
	level := convertFromString(cl.Level)
	l := &stdLogger{
		baselogger{
			tag:      LoggerTagUndefined,
			logLevel: level,
		},
	}
	l.Logger = l
	return l
}

func (l *stdLogger) LogEntry(logEntry map[string]any) {
	if l.logLevel == FATAL {
		log.Fatalf("%+v", logEntry)
	} else {
		log.Printf("%+v", logEntry)
	}
}

func (l *stdLogger) WithCustomTag(tag LoggerTag) Logger {
	nl := *l
	nl.tag = tag
	nl.Logger = &nl
	return &nl
}

func (l *stdLogger) WithCustomStrTag(tagstr string) Logger {
	return l.WithCustomTag(LoggerTag(tagstr))
}
